package cn.kgc.jdbc;

import cn.kgc.utils.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author mosin
 * date 2022/2/11
 * @version 1.0
 *
 */
public class JDBCDemo06 {

    public static void main(String[] args) {

        Connection connection = JDBCUtil.getConnection();
        PreparedStatement pstmt = null;
        String sql = "update usr set username = ? where id = ?";
        try {
             pstmt = connection.prepareStatement(sql);
             //设置参数
           pstmt.setString(1, "李四");
           pstmt.setInt(2, 5);
           int i = pstmt.executeUpdate();
           System.out.println("line = " + i);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            JDBCUtil.closeAll(null, pstmt, connection);
        }

    }
}
